using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public class ParseAnim : MonoBehaviour
{
    Vector3 oriPosition;
    Vector3 localEulerAngles;

    public AnimTransformData animTransformData;
    // Start is called before the first frame update
    void Start()
    {
        Init();
    }

    bool hasInit;
    public void Init()
    {
        if (hasInit)
            return;
        hasInit = true;

        animTransformData = ParseAnimData.Instance.Parse("MoveSkill");
        Application.targetFrameRate = 30;
        oriPosition = transform.localPosition;
        localEulerAngles = transform.localEulerAngles;
    }

    public void SampleAnimation(float time)
    {
        TransformData data = animTransformData.GetRealData(time);
        if (data != null)
        {
            Debug.Log(Time.time + ":" + data.position + "--" + data.rotation);
            transform.localPosition = oriPosition + data.position;
            transform.localEulerAngles = localEulerAngles + data.rotation;
        }
    }

    // Update is called once per frame
    void Update()
    {

        if (Input.GetKeyDown(KeyCode.Q))
        {
            var data = animTransformData.GetRealData(1);
            transform.localPosition = transform.localPosition + data.position; ;
            transform.localEulerAngles = transform.localEulerAngles + data.rotation;
        }
    }
}
